import Vue from 'vue'
const graceJS = require('@/GraceUI5/js/grace.js');
Vue.mixin({
  data(){
    return {
      dataOptions:[
        {
          text: '删除',
          style: {
            backgroundColor: '#f88742',
            color:'#fff',
            fontSize:"30rpx"
          }
        }
      ],
      artiveTitle:'',//活动标题
      artiveTitleLen:0,//活动标题
      camera:'/static/publishEmploy/camera.png',
      valueLen:0,//条数
      getCurPageList:[],//列表数据
      pageSize:10,//条数
      pageNo:1,//当前第几页
      searchTitle:'',//搜索的内容
      suggestion:'',//建议反馈的内容
      imgList:[],
      imgList1:[],
      imageList2:[],
      more:{
        status: 'loadmore', //加载的状态
        iconType: 'flower', //加载图标样式
        isLoading: false, //是否要加载数据
      },

      // 核心区域高度
      mainHeight   : 200,
      // 全屏 loading
      pageLoading : false,
    }
  },
  watch:{
    //标题
    artiveTitle(a,b){
      this.artiveTitleLen = a.length || 0
    },
    //300字
    suggestion(a,b){
      this.valueLen = a.length || 0
    },
  },
  methods:{
    //tabs切换
    navchange(index){
      this.currentIndex = index;
    },
    //重置操作
    onReset(){
      this.getCurPageList = []
      this.pageNo = 1
      this.more.status = 'loadmore'
      this.more.isLoading = false
      this.more.iconType='flower'
    },
    //列表数据
    async  getCurrentPageList(cb,params={},type='1') {
      if (this.more.isLoading) {
        return
      }
      this.more.isLoading = true
      this.more.status = 'loading'
      uni.showLoading({
        title: '加载数据中...',
        mask:true
      })
      if(type==='1'){
        const {
          code,
          result: { records: list, total },
        } = await cb(params)
        if (code === 200) {
          this.more.isLoading = false
          uni.hideLoading()

          if (!list.length) {
            this.more.status = 'nomore'
          } else {

            this.more.status = 'loadmore'
            this.getCurPageList = [...this.getCurPageList, ...list]
            this.getCurPageList.map(item=>{
              this.$set(item,'show',false)
            })
            if ( this.getCurPageList.length >= total) {
              this.more.status = 'nomore'
            }
          }
        } else {
          this.more.status = 'nomore'
        }
      }else {
        const {
          code ,
          result: list ,
        } = await cb (params)
        if (code === 200) {
          this.more.isLoading = false
          uni.hideLoading ()
          if ( !list.length) {
            this.more.status = 'nomore'
          } else {
            this.more.status = 'loadmore'
            this.getCurPageList=[...this.getCurPageList,...list]
            this.getCurPageList.map(item=>{
              this.$set(item,'show',false)
            })
            if (this.getCurPageList.length<10) {
              this.more.status = 'nomore'
            }
          }
        } else {
          this.more.status = 'nomore'
          uni.hideLoading ()
        }
      }

    },
    initGetRefs(){
      // 01. 获取页面主体高度
      graceJS.getRefs('guiPage', this, 0, (ref)=>{
        ref.getDomSize('guiPageBody', (e)=>{
          // 02. 导航的高度
          // 可以 使用 graceJS.select() 函数动态获取， 也可以使用 uni.upx2px 转换已知高度
          // 轮播主体高度 = 页面高度 - 导航高度
          this.mainHeight  = e.height - uni.upx2px(100);
        });
      });
    },
    //删除视频操作
    onVideoDel(){
      this.camera = '/static/publishEmploy/camera.png'
    },
    //上传视频图片
    onSelectIVideo(){
      uni.chooseVideo({
        count: 1,

        sourceType: ['camera', 'album'],
        success:res=>{
          const {height,
            width,
            tempFilePath,
            name,
            size,} = res
          let isSize = width<=1750 && height<=1280;
          if (!isSize) {
            this.$showToast("尺寸750*280")
            return
          }
          this.camera = tempFilePath

        }
      });
    },
    //上传1个视频
    onUpldateVideo(){
      this.$showLoading({
        title:'视频上传中..'
      })
      return new Promise((resolve, reject) => {
        const url = process.uniEnv.BASE_API+'em-boot/biz/api/sys/common/selfUpload'
        const filePath = this.camera
        uni.uploadFile({
          url,
          filePath,
          name: 'file', // 写死
          // 请求头一定要加，否则 iOS 图片上传会失败 安卓 可有可无
          header: {

            "X-Access-Token":this.$store.state.token,
          },
          // formData: {
          //   file: tempFilePath   // 这里一定不能加 file 加了 iOS 图片上传会失败 安卓无此问题
          // },
          success: (uploadFileRes) => {
            resolve(JSON.parse(uploadFileRes.data).message);

          },
          fail: (err) => {

            reject(err)
          }
        });
      })
    },

  }
})
